#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
const int N=1e9+50;
int t,n;
int main(void){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        priority_queue<int,vector<int>,greater<int>> q;
        map<int,int> vis;
        ll ans=0;
        ll cnt=0;
        int x;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            q.push(x);
            if(q.top()<x){
                cnt++;
                ans+=x-q.top();
                //看买入价格是否作为过卖出价格
                if(vis[q.top()]){
                    vis[q.top()]--;
                    cnt--;
                }
                q.pop();
                q.push(x);
                vis[x]++;
            }
        }
        printf("%lld %lld\n",ans,cnt*2);
    }
    return 0;
}